var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
    function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
    return new (P || (P = Promise))(function (resolve, reject) {
        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
        function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
(function (factory) {
    if (typeof module === "object" && typeof module.exports === "object") {
        var v = factory(require, exports);
        if (v !== undefined) module.exports = v;
    }
    else if (typeof define === "function" && define.amd) {
        define(["require", "exports", "./service", "config"], factory);
    }
})(function (require, exports) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    const service_1 = require("./service");
    const config_1 = require("config");
    let { protocol } = location;
    class MemberService extends service_1.Service {
        authUrl(path) {
            let url = `${protocol}//${config_1.config.serviceHost}/auth/${path}`;
            return url;
        }
        url(path) {
            let url = `${config_1.config.memberUrl}${path}`;
            return url;
        }
        // login(username: string, password: string) {
        //     password = md5(password);
        //     let url = this.authUrl('user/login');
        //     return this.postByJson<LoginResult>(url, { username, password })
        //         .then(d => {
        //             Service.token.value = d.token;
        //         });
        // }
        // async register(mobile: string, password: string, smsId: string, verifyCode: string) {
        //     let url = `user/register`;
        //     let result = await this.postByJson<{ token: string, userId: string, appToken: string }>(url, {
        //         mobile, password, smsId, verifyCode
        //     })
        //     Service.token.value = result.token;
        //     return result;
        // }
        // async registerById(sellerId: string) {
        //     console.assert(sellerId != null);
        //     let url = `${Service.config.memberUrl}Seller/RegisterById`;
        //     let result = await this.postByJson<LoginResult>(url, { sellerId });
        //     Service.token.value = result.token;
        //     return result;
        // }
        // async resetPassword(mobile, password, smsId, verifyCode) {
        //     let url = `user/resetPassword`;
        //     let result = await this.postByJson<{ token: string, userId: string, appToken: string }>(url, { mobile, password, smsId, verifyCode })
        //     Service.token.value = result.token;
        //     return result;
        // }
        isMobileRegister(mobile) {
            let url = `user/isMobileRegister`;
            return this.get(url, { mobile });
        }
        sendVerifyCode(mobile, type) {
            let url = `sms/sendVerifyCode`;
            return this.postByJson(url, { mobile, type });
        }
        //============================================================
        // 店铺
        addStore(app) {
            let url = this.authUrl('application/add');
            return this.postByJson(url, { name: app.Name }).then(data => {
                Object.assign(app, data);
                return data;
            });
        }
        updateStore(app) {
            let url = this.authUrl('application/update');
            return this.putByJson(url, app);
        }
        deleteStore(app) {
            console.assert(app != null);
            let url = this.authUrl('application/remove');
            return this.deleteByJson(url, { id: app.Id });
        }
        saveStore(store) {
            return __awaiter(this, void 0, void 0, function* () {
                // let url = `${Service.config.memberUrl}Seller/UpdateApplication`
                // return this.postByJson(url, { app: store });
                // return this.updateStore(store)
                let url = this.url("Application/Save");
                let r = yield this.postByJson(url, { app: store });
                Object.assign(store, r);
                return r;
            });
        }
        /**
         * 获取店铺
         */
        getStore() {
            return __awaiter(this, void 0, void 0, function* () {
                // if (!storeId) throw errors.argumentNull('storeId')
                console.assert(this.applicationId != null);
                let url = this.url("Application/Item");
                let r = yield this.get(url, { id: this.applicationId });
                return r;
            });
        }
        stores() {
            return __awaiter(this, void 0, void 0, function* () {
                let url = this.url("Application/List");
                let r = yield this.get(url);
                return r;
            });
        }
    }
    exports.MemberService = MemberService;
});
// export default new UserService();
